import type { NextApiResponse } from 'next';
import * as categoryService from '@/common/service/g_category';
import { AuthenticatedRequest, withAuth } from '@common/middleware/auth';

export async function handler(req: AuthenticatedRequest, res: NextApiResponse) {
  if (req.method === 'GET') {
    const { _start = 0, _end = 10 } = req.query;
    const data = await categoryService.getCategoryList({}, Number(_start), Number(_end));
    res.status(200).json({ success: true, data });
  } else if (req.method === 'POST') {
    const id = await categoryService.createCategory(req.body);
    res.status(200).json({ success: true, id });
  } else {
    res.status(405).json({ success: false, message: 'Method Not Allowed' });
  }
}

export default withAuth(handler); 